package mysql

import "gorm.io/gorm"

type UserInfo struct {
	gorm.Model
	PhoneNum   string `gorm:"type:varchar(20);not null;unique;comment:手机号"`
	Password   string `gorm:"type:varchar(20);not null;comment:密码"`
	NickName   string `gorm:"type:varchar(20);not null;;comment:昵称"`
	AvatarLink string `gorm:"type:varchar(500);not null;;comment:头像"`
	FollowNum  int    `gorm:"type:int(11);default:0;comment:关注数"`
	FansNum    int    `gorm:"type:int(11);default:0;comment:粉丝数"`
}

func (i *UserInfo) LoginUser(db *gorm.DB, num string) error {
	return db.Where("phone_num=?", num).First(i).Error
}

func (i *UserInfo) RegisterUser(db *gorm.DB, num string) interface{} {
	return db.Where("phone_num=?", num).Find(i).Error
}

func (i *UserInfo) UserAdd(db *gorm.DB) error {
	return db.Create(i).Error
}

func (i *UserInfo) FindUserById(db *gorm.DB, id int64) error {
	return db.Where("user_infos.id=?", id).First(i).Error
}

func (i *UserInfo) UpdatePassword(db *gorm.DB) error {
	return db.Updates(i).Error
}
